<%@ page contentType="text/html; charset=WINDOWS-1256" pageEncoding="WINDOWS-1256" %>
<%@ taglib uri="isomorphic" prefix="isomorphic" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt"  uri="http://java.sun.com/jsp/jstl/fmt" %>


<jsp:useBean id="user" class="qa.gov.moi.erp.util.dto.UserDTO" scope="session" />
<c:choose>
    <c:when test="${param.dir=='ltr'}">
		<fmt:setLocale scope="session" value="en"/>
		<c:set var="currentDir" value="ltr"  scope="session" />
		<c:set var="otherDir" value="rtl"  scope="session" />
		<jsp:setProperty name="user" property="lang" value="en"/>	
	</c:when>
    <c:otherwise>
    	<c:set var="currentDir" value="rtl"  scope="session" />
    	<c:set var="otherDir" value="ltr"  scope="session" />
        <fmt:setLocale scope="session" value="ar"/>
        <jsp:setProperty name="user" property="lang" value="ar"/>
    </c:otherwise>
</c:choose>





<fmt:setBundle scope="session" basename="qa.gov.moi.erp.web.resources.messages"/>

<c:set var="imgLoc" value="${pageContext.request.contextPath}/common/images"  scope="application"/>
<c:set var="cssLoc" value="${pageContext.request.contextPath}/common/css" scope="application"/>
<c:set var="jsLoc" value="${pageContext.request.contextPath}/common/js" scope="application"/>




<%@page import="java.util.ArrayList"%>
<%@page import="qa.gov.moi.erp.util.dto.DocumentConfigurationDTO"%>
<%@page import="qa.gov.moi.erp.core.framework.LookUpManager"%>
<html dir="${currentDir}"> <head> 

<title>ERP Systems - MOI</title>
<%

response.setHeader("pragma", "no-cache");
response.setDateHeader("Expires", 0);
response.setHeader("Cache-control", "no-cache, no-store, must-revalidate");

%>


<style type='text/css'>
td.tab, td.tabSelected{
	padding:3px 10px;
}
table.listTable td{
	cursor:pointer;
	cursor:hand;
}
table.listTable td.groupNode{
	cursor:auto;
}

.error{color:red}
.info{color:green;fontsize:1px}
.warn{color:blue}
</style>
<isomorphic:loadISC skin="TreeFrog"/>
<SCRIPT SRC='isomorphic/system/modules/ISC_Charts.js?isc_version=v8.2p_2012-06-02.js'></SCRIPT>
</head> 
<body scroll='no' onload="openTabs();">
<script type='text/javascript'>


Array.prototype.unique =
  function() {
    var a = [];
    var l = this.length;
    for(var i=0; i<l; i++) {
      for(var j=i+1; j<l; j++) {
        // If this[i] is found later in the array
        if (this[i] === this[j])
          j = ++i;
      }
      a.push(this[i]);
    }
    return a;
  };

function openTabs(){

	if (Page.isLoaded()){
<%
	String[] tabs = request.getParameterValues("tab");
	if (tabs!=null){
	for(String tab : tabs){
	if (!tab.equals("0")){
%>
	
	loadTabData(<%=tab%>);
<%}}}%>

	}else{
		setTimeout("test()",500);
	}
} 

function test(){

	if (Page.isLoaded()){
		openTabs();
	}else{
		setTimeout("test()",500);
	}

}




function loadTabData(actionpathId){
	if(actionpathId==1){
		loadDataFromJsp("tabMenuMgmnt",'<fmt:message key="menu.moiProducts"/>',"RND/Products.jsp",actionpathId);
	}
	else if(actionpathId==2){
		loadDataFromJsp("tabRoleAccess",'<fmt:message key="menu.roleAccess"/>',"RND/ameen.jsp",actionpathId); 
	}
	else if(actionpathId==3){
		loadDataFromJsp("RequisitionsTab",'Requisitions',"RND/Requisition.jsp",actionpathId); 
	}
	else if(actionpathId==4){
		loadDataFromJsp("tabShowItems",'<fmt:message key="menu.example"/>',"jsp-files/items-list.jsp",actionpathId); 
	}
	else if(actionpathId==5){
		loadDataFromJsp("IssueItemsTab",'Item Issue',"RND/ItemIssue1.jsp",actionpathId); 
	}else if(actionpathId==6){
		loadDataFromJsp("RequisitionsManagerTab",'Requisitions By manager',"RND/RequisitionSecondRole.jsp",actionpathId); 
	}else if(actionpathId==7){
		loadDataFromJsp("NEWREQUISITIONTab",'NEW REQUISITION',"RND/OLDGUI/NewRequisition.jsp",actionpathId); 
	}else if(actionpathId==8){
		loadDataFromJsp("TESTREQUISITIONTab",'TEST REQUISITION',"RND/NewRequisition1.jsp",actionpathId); 
	}
	else if(actionpathId==9){
		loadDataFromJsp("ProductsTab",'ProductsTree',"RND/TestLayout.jsp",actionpathId); 
	}
	else if(actionpathId==10){
		loadDataFromJsp("AuditTrailTab",'AuditTrail',"RND/AuditTrail.jsp",actionpathId);
		 
	}else if(actionpathId==11){
		loadDataFromJsp("UsersTab",'Users',"RND/Configurations/usersSetup.jsp",actionpathId);
		 
	}else if(actionpathId==12){
		loadDataFromJsp("RolesTab",'Roles',"RND/Configurations/rolesSetup.jsp",actionpathId);
		 
	}else if(actionpathId==13){
		loadDataFromJsp("PermissionsTab",'Permissions',"RND/Configurations/permissionsSetup.jsp",actionpathId); 
		
	}else if(actionpathId==14){
		loadDataFromJsp("statusesTab",'Statuses',"RND/Configurations/statusesSetup.jsp",actionpathId); 
		
	}else if(actionpathId==15){
		loadDataFromJsp("documentsTab",'Documents',"RND/Configurations/documentsSetup.jsp",actionpathId);
		 
	}else if(actionpathId==16){
		loadDataFromJsp("actionsTab",'Actions',"RND/Configurations/actionButtonsSetup.jsp",actionpathId);
		 
	}else if(actionpathId==17){
		loadDataFromJsp("StatusRolesTab",'DOCUMENT STATUS ROLE ACTIONS',"RND/Configurations/documentStatusRolesSetup.jsp",actionpathId); 
	}
	
	
	
	
	return false;
}


Page.setAppImgDir("common/images/");

function callSwitchingServlet(value){

	
	document.location.href="${pageContext.request.contextPath}/RoleSwitchingServlet?role="+value+"&dir=${currentDir}";
}
function menuItemClick(item, colNum) {
	if (item.name) {
		if(item.pagePath){
			isc.say("Loading... " + item.pagePath);
		}
		else if(item.name='menuItemAddTab'){
			isc.say("Functionality not implemented yet. ");
		}
		this.hide();
	}
}
function loadDataFromJsp(tabId, tabTitle, pagePath,actionId){
	if(tabBarBody.getTab(tabId)==null){
		tabBarBody.addTab({
			ID:tabId,
			title: tabTitle,
			actionId:actionId,
			canClose:true,
			align:"right",
			pane:isc.HLayout.create({
				autoDraw: false,
				layoutMargin: 0,
				
				members: [
					isc.HTMLPane.create({
						width:"100%",
						contentsURL:pagePath,
						contentsType: 'page',
						overflow:"auto",
						styleName:"defaultBorder"
					})
				]
			})
		});
	}
	tabBarBody.selectTab(tabId);
}

isc.Menu.create({
	ID: "menuItemsApp",
	autoDraw: false,
	showShadow: true,
	shadowDepth: 10,
	data: [
	
		{
			name:'menuItemMenu', title: 'Item Issue',
			click:function(){
				loadTabData(5); 
			}
		},
	
		{
			name:'menuItemMenu', title: '<fmt:message key="menu.moiProducts"/>',
			click:function(){
				loadTabData(1); 
			}
		},
		{
			name:'menuItemRoleAccess', title: '<fmt:message key="menu.roleAccess"/>',
			click:function(){
				loadTabData(2);
			}
		},
		{
			name:'menuItemReports', title: 'Requisitions',
			click:function(){
				loadTabData(3);
			}
		}/*,
		{isSeparator: true},
		{
			title: "Windows", 
			submenu: 
			[
				{name:'menuSubItem1', title: "data.xml", pagePath:'helloOne.jsp'},
				{name:'menuSubItem2', title: "Component Guide.doc"},
				{name:'menuSubItem3', title: "SmartClient.doc"},
				{title: "AJAX.doc"}
			]
		}*/
	]
});


var rolesArray = new Array();
<c:forEach items="${user.roles}" var="role">
	rolesArray.push('<c:out value="${role}" />');
</c:forEach>

var documentAuthorizations = new Array();
var documentTypes = new Array();

<%

	ArrayList<DocumentConfigurationDTO> 	documentConfigurations = LookUpManager.getInstance().getDocumentsConfiguration();
	pageContext.setAttribute("documentConfigurations",documentConfigurations); 
%>

<c:forEach items="${documentConfigurations}" var="documentConfiguration">
	<c:if test="${documentConfiguration.statusRole==user.currentRole.name}">  
		documentAuthorizations.push('<c:out value="${documentConfiguration.statusRole}" />-<c:out value="${documentConfiguration.documnetType}" />-<c:out value="${documentConfiguration.documnetStatus}" />-<c:out value="${documentConfiguration.statusRoleAction}" />');
	</c:if>
	documentTypes.push('<c:out value="${documentConfiguration.statusRoleAction}" />');		
</c:forEach>



function showActions(){

	
}

documentTypes = documentTypes.unique();


for(var i=0;i<documentTypes.length;i++){
	//alert(documentTypes[i]);
}



isc.VLayout.create({
    width: "100%",
    height: "100%",
     ID:"mainView",
    members: [
        isc.HLayout.create({
            width: "100%",
			height:"10%",
            members: [
                isc.Label.create({
                    contents: '<fmt:message key="label.wellcome"/> ${user.name} login as ${user.currentRole.name}',
					//left:10, top:2,
					width:"180",
					 //defaultLayoutAlign: "center", 
					 <c:if test="${currentDir=='rtl'}">
	                     align: "right",
					</c:if>                     
					valign:"top",
					margin:3
                }),
                isc.MenuButton.create({
					ID: "btnApplicationMenu",
					title: '<fmt:message key="menu.application"/>',
					width: 120,
					menu: menuItemsApp
				}),
				isc.MenuButton.create({
					ID: "btnShowItems",
					title: '<fmt:message key="menu.example"/>',
					width: 120,
					click:function(){
						loadTabData(4); 
					}
				}),
				isc.MenuButton.create({
					ID: "btnEditHelp",
					title: '<fmt:message key="menu.language"/>',
					width: 120,
					click:function(){
					
						
						
						var urlExtra = "";
						
							var tabs = tabBarBody.tabs;
							
							for(var i=0;i<tabs.length;i++){
							
								urlExtra = urlExtra + "tab="+tabs[i].actionId+"&";
								
							}
							
							urlExtra = (urlExtra=='')?'':"&"+urlExtra;
						
							
							
						location.href="index.jsp?dir=${otherDir}"+urlExtra;
					}
				}),
				
				isc.HLayout.create({
	            width: "100%",
				height:"10%",
				align: "center",  
	            members: [
	            
	            
				isc.Label.create({
                    contents: 'login as ',
					//left:10, top:2,
					//width:"180",
					 //defaultLayoutAlign: "center", 
					 <c:if test="${currentDir=='rtl'}">
	                     align: "right",
					</c:if>                     
					valign:"top",
					margin:3
                }),
                
                isc.DynamicForm.create({
				    width:200, minWidth:100,
				    numCols:1,
				    fields: [  {name: "selectZoom", type: "select" , showTitle: false, width:"*", valueMap: rolesArray,defaultValue:"${user.currentRole.name}" ,changed:"callSwitchingServlet(value)"}   ]
				})
                
                
                
               
                	            
	            
	            
	            ]
	            
	            
	            })				
				
				
				
            ]
        }),
        isc.HLayout.create({
            width: "100%",
            members: [
                isc.DataView.create({
					ID:"dataViewMainLayout",
					autoDraw:true,
					overflow:"hidden",
					members:[
						isc.TabSet.create({
							ID:"tabBarBody",
							autoDraw:false,
							tabBarPosition: "top",
							tabs:[
								{
									ID:"tabWorkspace",
									actionId:0,
									title:'<fmt:message key="label.workspace"/>',
									pane:isc.HLayout.create({
										autoDraw: false,
										layoutMargin: 0,
										membersMargin: 5,
										members: [
											isc.HTMLPane.create({
												ID:"helpCanvas11",
												width:210,
												contentsURL:"jsp-files/left-menu.jsp",
												overflow:"none",
												styleName:"defaultBorder"
											}),
											isc.HTMLPane.create({
												ID:"helpCanvas12",
												contentsURL:"jsp-files/home.jsp",
												overflow:"auto",
												styleName:"defaultBorder"
											})
										]
									})
								}
							],
							destroyPanes:false
						})
					],
					width:"100%",
					height:"100%"
				})
			]
        }),
		isc.Label.create({
            contents: '<fmt:message key="label.developedBy"/>',
            align: "center",
            overflow: "hidden",
            width: "100%",
			height:30,
			icon: "${imgLoc}/remove.png",
			baseStyle:"info",
            border: "1px solid gray",
            click:function(){
            	if (this.contents!=''){
            	isc.say(this.contents);
            	}
            },
            iconClick:function(){
            	this.setContents('');
            	this.setIcon(null);
            	
            } 
           
        })
    ]
});

function setFooterContent(val,type){
	
	if (type!=null){

		mainView.getMember(2).setBaseStyle(type);
	}
	 
	mainView.getMember(2).setIcon("${imgLoc}/remove.png");
	mainView.getMember(2).setContents(val);
}
</script> 
</body>
</html>